/**
 * 
 */
package com.tw.trips.domain;

import static org.neo4j.graphdb.Direction.INCOMING;

import java.util.Collection;
import java.util.Date;
import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.template.Neo4jOperations;

/**
 * @author m1005264
 * 
 */
@NodeEntity
public class Update {

	private static final String COMMENTED = "COMMENTED";

	@GraphId
	private Long nodeiD;

	@RelatedTo(type = "UPDATED", direction = Direction.OUTGOING)
	@Fetch
	public Traveller updatedBy;

	@RelatedTo(type = "UPDATED", direction = INCOMING)
	@Fetch
	public Location forLocation;

	private Date createdOn;

	private String message;

	private String imgURL;

	@RelatedTo(type = COMMENTED, elementClass = Comment.class, direction = INCOMING)
	@Fetch
	Set<Comment> comments;

//	@RelatedTo(type = "UPDATED_BY", elementClass = Trip.class, direction = INCOMING)
//	@Fetch
//	Trip trip;

	@RelatedTo(type = "ITHELPS", elementClass = ItHelps.class, direction = INCOMING)
	@Fetch
	Set<ItHelps> itHelps;

	public Update(String msg, String imgURL, Date createdOn) {
		this.message = msg;
		this.imgURL = imgURL;
		this.createdOn = createdOn;
	}

	public Comment comment(Neo4jOperations template, Traveller commentedBy,
			Date commentedOn, String message) {
		final Comment comment = template.createRelationshipBetween(commentedBy,
				this, Comment.class, COMMENTED, false).comment(commentedOn,
				message);
		return template.save(comment);
	}

	public void addComment(Comment comment) {
		comment.setUpdate(this);
	}

	public void addItHelps(ItHelps helps) {
		itHelps.add(helps);
	}

	public Long getNodeiD() {
		return nodeiD;
	}

	public void setNodeiD(Long nodeiD) {
		this.nodeiD = nodeiD;
	}

	public Traveller getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(Traveller updatedBy) {
		this.updatedBy = updatedBy;
	}

	public Location getForLocation() {
		return forLocation;
	}

	public void setForLocation(Location forLocation) {
		this.forLocation = forLocation;
	}

	public Date getCreatedOn() {
		return createdOn;
	}

	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getImgURL() {
		return imgURL;
	}

	public void setImgURL(String imgURL) {
		this.imgURL = imgURL;
	}

	public Collection<Comment> getComments() {
		return comments;
	}

	public Collection<ItHelps> getItHelps() {
		return itHelps;
	}

	public Update() {
		super();
	}

	public Update(String msg, String imgURL) {
		this.message = msg;
		this.imgURL = imgURL;
	}

//	/**
//	 * @return the trip
//	 */
//	public Trip getTrip() {
//		return trip;
//	}
//
//	/**
//	 * @param trip
//	 *            the trip to set
//	 */
//	public void setTrip(Trip trip) {
//		this.trip = trip;
//	}

}
